#include "library/enterprisestart.bas"

asm
ld sp,$0100
di
end asm

#include "library/smsrnd.bas"
#include "library/smsdelay.bas"
#include "library/b1r0f0_charmapminivaders01.bas"
#include "library/fillramadd.bas"
#include "library/ldiradd.bas"

dim eee as uinteger at $1F10
dim seed as uinteger at $1F12
dim ee0 as uinteger at $1F14
dim ee1 as uinteger at $1F16
dim ee2 as uinteger at $1F18
dim ee3 as uinteger at $1F1A
dim eex as uinteger at $1F1C
dim eey as uinteger at $1F1E
dim ee4 as uinteger at $1F20

sub enterpriseputcharattrmode(txp1 as uinteger,typ1 as uinteger,tch1 as uinteger,tat1 as ubyte,tad1 as uinteger):
  ldiradd($DF40+txp1+(typ1*320),tad1+(tch1*8),8,40)
  fillramadd($C000+txp1+(typ1*320),tat1,8,40)
  end sub

for ee0=$FF08 to $FF0F
  seed=smsrnd(seed)
  poke ee0,seed
  next
seed=smsrnd(seed):out $80,seed band %00011111


  for ee0=0 to 24
    for ee1=0 to 39
      ee2=seed:seed=smsrnd(seed)
      ee2=seed:seed=smsrnd(seed)
      enterpriseputcharattrmode(ee1,ee0,seed mod 4,ee2,@charmap01-256)
      seed=smsrnd(seed)
      next:next

  for ee0=0 to 15
    for ee1=0 to 15
      ee2=ee0*16+ee1
      enterpriseputcharattrmode(ee1+23,ee0+8,ee2,$12,@charmap01-256)
      seed=smsrnd(seed)
      next:next

eee=0:eex=8:eey=8
do
  enterpriseputcharattrmode(1,1,48+(int(eee/10000) mod 10),$12,@charmap01-256)
  enterpriseputcharattrmode(2,1,48+(int(eee/1000) mod 10),$12,@charmap01-256)
  enterpriseputcharattrmode(3,1,48+(int(eee/100) mod 10),$12,@charmap01-256)
  enterpriseputcharattrmode(4,1,48+(int(eee/10) mod 10),$12,@charmap01-256)
  enterpriseputcharattrmode(5,1,48+(eee mod 10),$12,@charmap01-256)

  out $B5,0
  ee1=in($B5) bxor $FF
  enterpriseputcharattrmode(3,3,48+(int(ee1/100) mod 10),$12,@charmap01-256)
  enterpriseputcharattrmode(4,3,48+(int(ee1/10) mod 10),$12,@charmap01-256)
  enterpriseputcharattrmode(5,3,48+(ee1 mod 10),$12,@charmap01-256)

  out $B5,1
  ee1=in($B5) bxor $FF
  enterpriseputcharattrmode(3,4,48+(int(ee1/100) mod 10),$12,@charmap01-256)
  enterpriseputcharattrmode(4,4,48+(int(ee1/10) mod 10),$12,@charmap01-256)
  enterpriseputcharattrmode(5,4,48+(ee1 mod 10),$12,@charmap01-256)

  eex=eex-((ee1 band 64)/64)+((ee1 band 8)/8)
  eey=eey+((ee1 band 32)/32)
  
  out $B5,2
  ee1=in($B5) bxor $FF
  enterpriseputcharattrmode(3,5,48+(int(ee1/100) mod 10),$12,@charmap01-256)
  enterpriseputcharattrmode(4,5,48+(int(ee1/10) mod 10),$12,@charmap01-256)
  enterpriseputcharattrmode(5,5,48+(ee1 mod 10),$12,@charmap01-256)

  eey=eey-((ee1 band 64)/64)

  enterpriseputcharattrmode(eex,eey,(eee mod 106),$12,@charmap01-256)

  eee=eee+1
  loop





do:loop

do

for ee0=$FF08 to $FF0F
  seed=smsrnd(seed)
  poke ee0,seed
  next
seed=smsrnd(seed):out $80,seed band %00011111

for ee0=0 to 24
  for ee1=0 to 39
    seed=smsrnd(seed):ee2=seed
    seed=smsrnd(seed)
    enterpriseputcharattrmode(ee1,ee0,seed mod 74,ee2,@charmap01)
    next:next

loop

do:loop

do





for ee0=0 to 24
  for ee1=0 to 39
    for ee2=0 to 7
      seed=smsrnd(seed):poke $C000+(ee2*40)+ee1+(ee0*320),seed
      seed=smsrnd(seed):poke $DF40+(ee2*40)+ee1+(ee0*320),seed
      smsdelay(100)
      next:next:next




for ee0=$C000 to $FEFF
  seed=smsrnd(seed)
  poke ee0,seed
  next

loop





do:loop

eee=0
do
  for ee0=0 to 49
    for ee1=0 to 79
      for ee2=0 to 3
        poke $C000+(ee2*80)+ee1+(ee0*320),eee
        next
      smsdelay(1000)
      eee=eee+1
      next:next
  for ee0=0 to 49
    for ee1=0 to 79
      seed=smsrnd(seed)
      for ee2=0 to 3
        poke $C000+(ee2*80)+ee1+(ee0*320),seed
        next
      smsdelay(1000)
      next:next
  loop



do
  for ee0=0 to 24
    for ee1=0 to 39
      seed=smsrnd(seed)
      for ee2=0 to 7
        for ee3=0 to 1
          poke $C000+(ee2*80)+ee3+(ee1*2)+(ee0*640),peek(@charmap01+ee2*2+ee3+((seed mod 8)*16))
          next:next
      seed=smsrnd(seed)
      if (seed mod 20)<2 then:
        for ee4=0 to 7:
          seed=smsrnd(seed):poke $FF08+ee4,seed
          next
        seed=smsrnd(seed):out $80,seed
        end if
      smsdelay(10000)
      next:next
  loop

do
  for ee0=0 to 24
    for ee1=0 to 39
      for ee2=0 to 7
        for ee3=0 to 1
          seed=smsrnd(seed)
          poke $C000+(ee2*80)+ee3+(ee1*2)+(ee0*640),seed
          next:next
      smsdelay(10000)
      next:next
  loop

do:loop



